package robocup.component.speechacts.coachlanguage;

import java.util.LinkedList;

public class CoachSayAction {

  private TypeConstants.MESSAGETYPE messageType     = TypeConstants.MESSAGETYPE.INIT;

  private String                    freeformMessage = "";

  private RuleMessage               ruleMessage     = null;

  private AdviceMessage             adviceMessage   = null;

  private InfoMessage               infoMessage     = null;

  private MetaMessage               metaMessage     = null;

  private DeleteMessage             deleteMessage   = null;

  private LinkedList<DefineMessage> defineList      = new LinkedList<DefineMessage>();

  public CoachSayAction() {

  }

  public TypeConstants.MESSAGETYPE getMessageType() {

    return this.messageType;
  }

  public void setMessageType(final TypeConstants.MESSAGETYPE messageType) {

    this.messageType = messageType;
  }

  public RuleMessage getRuleMessage() {

    return this.ruleMessage;
  }

  public void setRuleMessage(final RuleMessage ruleMessage) {

    this.ruleMessage = ruleMessage;
    this.messageType = TypeConstants.MESSAGETYPE.RULE;
  }

  public String getFreeformMessage() {

    return this.freeformMessage;
  }

  public void setFreeformMessage(String freeformMessage) {

    if (freeformMessage.startsWith("\"")) {
      freeformMessage = freeformMessage.substring(1,
          freeformMessage.length() - 1);
    }
    this.freeformMessage = freeformMessage;
    this.messageType = TypeConstants.MESSAGETYPE.FREEFORM;
  }

  public void addDefine(final DefineMessage define) {

    this.defineList.add(define);
    this.messageType = TypeConstants.MESSAGETYPE.DEFINE;
  }

  public LinkedList<DefineMessage> getDefineList() {

    return this.defineList;
  }

  public void setDefineList(final LinkedList<DefineMessage> defineList) {

    this.defineList = defineList;
    this.messageType = TypeConstants.MESSAGETYPE.DEFINE;
  }

  public AdviceMessage getAdviceMessage() {

    return this.adviceMessage;
  }

  public void setAdviceMessage(final AdviceMessage adviceMessage) {

    this.adviceMessage = adviceMessage;
    this.messageType = TypeConstants.MESSAGETYPE.ADVICE;
  }

  public InfoMessage getInfoMessage() {

    return this.infoMessage;
  }

  public void setInfoMessage(final InfoMessage infoMessage) {

    this.infoMessage = infoMessage;
    this.messageType = TypeConstants.MESSAGETYPE.INFO;
  }

  public MetaMessage getMetaMessage() {

    return this.metaMessage;
  }

  public void setMetaMessage(final MetaMessage metaMessage) {

    this.metaMessage = metaMessage;
    this.messageType = TypeConstants.MESSAGETYPE.META;
  }

  public DeleteMessage getDeleteMessage() {

    return this.deleteMessage;
  }

  public void setDeleteMessage(final DeleteMessage deleteMessage) {

    this.deleteMessage = deleteMessage;
    this.messageType = TypeConstants.MESSAGETYPE.DELETE;
  }

  @Override
  public String toString() {

    final StringBuffer buf = new StringBuffer();

    buf.append("(say ");

    switch (this.messageType) {

      case INIT:
        buf.append("empty");
        break;

      case FREEFORM:
        buf.append("(freeform \"" + this.freeformMessage + "\")");
        break;

      case RULE:
        buf.append(this.ruleMessage.toString());
        break;

      case DELETE:
        buf.append(this.deleteMessage.toString());
        break;

      case DEFINE:
        buf.append("(define");
        for (final DefineMessage dm : this.defineList) {
          buf.append(" " + dm.toString());
        }
        buf.append(")");
        break;

      case META:
        buf.append(this.metaMessage.toString());
        break;

      case ADVICE:
        buf.append(this.adviceMessage.toString());
        break;

      case INFO:
        buf.append(this.infoMessage.toString());
        break;
    }

    buf.append(")");
    return buf.toString();
  }

}
